package com.gt.wc

import com.gt.SCUtil
import org.apache.log4j.Logger
import org.apache.spark.rdd.RDD

object WorldCount_03 {
  private val logger: Logger = Logger.getLogger("WorldCount_02")

  def main(args: Array[String]): Unit = {
    val sc = SCUtil.createLocalSc()
    val rdd1: RDD[String] = sc.makeRDD(Seq("a", "b", "c"))
    val rdd2: RDD[(String, Int)] = rdd1.map(x => (x, 1))

    val rdd3: RDD[(String, Iterable[Int])] = rdd2.groupByKey()
    val rdd4: RDD[(String, Int)] = rdd2.reduceByKey((a, b) => a + b)

    val rdd5: RDD[(String, Int)] = rdd2.coalesce(2, true)
    rdd5.aggregateByKey(0)(
      (x,y) => math.max(x,y),
      (x,y) => (x+y)
    )

    rdd2.reduceByKey(_+_)
    rdd2


    sc.stop()
  }

}
